package test.br.com.lh.urabuilder.util.pointChooser
{
	import br.com.lh.urabuilder.model.UraModelLocator;
	import br.com.lh.urabuilder.util.pointchooser.TwoComponentPointChooser;
	import br.com.lh.urabuilder.view.ActionComponent;
	
	import flexunit.framework.TestCase;
	import flexunit.framework.TestSuite;

	public class TwoComponentPointChooserTest extends TestCase
	{
		private var twoComponentPointChooser:TwoComponentPointChooser;
		
		public function TwoComponentPointChooserTest(methodName:String=null)
		{
			super(methodName);
		}
		
		public static function suite():TestSuite{
			var ts:TestSuite = new TestSuite();
			ts.addTest(new TwoComponentPointChooserTest("shouldChooseBottomAndTopPoints"));
			ts.addTest(new TwoComponentPointChooserTest("shouldChooseLeftAndRight"));
			ts.addTest(new TwoComponentPointChooserTest("shouldChooseLeftAndTop"));
			return ts;
		}
		
		private function initComponent(component:ActionComponent,x:Number,y:Number):void{
			component.loadComponent("PlaySound",x,y,0,0);
			UraModelLocator.getInstance().parent.addChild(component);
			component.image.executeBindings();
			component.buildPoints();
		}
		
		public function shouldChooseBottomAndTopPoints():void{
			var startComponent:ActionComponent = new ActionComponent();		
			var endComponent:ActionComponent = new ActionComponent();
			initComponent(startComponent,0,0);
			initComponent(endComponent,100,0);		
			twoComponentPointChooser = new TwoComponentPointChooser(startComponent,endComponent);
			var pointArray:Array = twoComponentPointChooser.pointArray;
			assertEquals(startComponent.pointBuilder.bottomPoint.x,pointArray[0].x);	
			assertEquals(startComponent.pointBuilder.bottomPoint.y,pointArray[0].y);	
			assertEquals(endComponent.pointBuilder.topPoint.x,pointArray[1].x);	
			assertEquals(endComponent.pointBuilder.topPoint.y,pointArray[1].y);	
		}

		public function shouldChooseLeftAndRight():void{
			var startComponent:ActionComponent = new ActionComponent();		
			var endComponent:ActionComponent = new ActionComponent();
			initComponent(startComponent,100,0);
			initComponent(endComponent,50,0);
			twoComponentPointChooser = new TwoComponentPointChooser(startComponent,endComponent);
			var pointArray:Array = twoComponentPointChooser.pointArray;
			assertEquals(startComponent.pointBuilder.leftPoint.x,pointArray[0].x);	
			assertEquals(startComponent.pointBuilder.leftPoint.y,pointArray[0].y);	
			assertEquals(endComponent.pointBuilder.rightPoint.x,pointArray[1].x);	
			assertEquals(endComponent.pointBuilder.rightPoint.y,pointArray[1].y);	
		}
		
		public function shouldChooseLeftAndTop():void{
			var startComponent:ActionComponent = new ActionComponent();		
			var endComponent:ActionComponent = new ActionComponent();
			initComponent(startComponent,100,0);
			initComponent(endComponent,50,100);
			twoComponentPointChooser = new TwoComponentPointChooser(startComponent,endComponent);
			var pointArray:Array = twoComponentPointChooser.pointArray;
			assertEquals(startComponent.pointBuilder.leftPoint.x,pointArray[0].x);	
			assertEquals(startComponent.pointBuilder.leftPoint.y,pointArray[0].y);	
			assertEquals(endComponent.pointBuilder.rightPoint.x,pointArray[1].x);	
			assertEquals(endComponent.pointBuilder.rightPoint.y,pointArray[1].y);	
		}
		
	}
}